package com.five.spring;

import com.five.util.DESUtil;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * Created by Administrator on 2018/1/19.
 */

public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

    private String[] encryptPropNames = {"jdbc.password","redis.pass"};

    @Override
    protected String convertProperty(String propertyName, String propertyValue) {

        if (isEncryptProp(propertyName)){
            String decryptValue = DESUtil.getDecryptString(propertyValue);
            return decryptValue;
        }else {
            return propertyValue;
        }

    }

    private boolean isEncryptProp(String propertyName){
        for (String encryptPropName:encryptPropNames) {
            if (encryptPropName.equals(propertyName)){
                return true;
            }
        }
        return false;
    }
}
